<?php	
	require_once __DIR__."/../Models/project.php";
	
	use Symfony\Component\HttpFoundation\Request;
	use Symfony\Component\HttpFoundation\Response;
	use Symfony\Component\HttpKernel\HttpKernelInterface;

	$project_model = new Models\project($app);
	$project = $app['controllers_factory'];

	echo "project ";

	$project->get('/{id}', function($id) use ($app, $project_model){
		echo $id;
		$prj = $project_model->getOne($id);

		$base_url = $app['homepage_route'];
		$user_var = $app['session']->get('user_var');
		$dir = __DIR__.'/../../views/imgsrc';	
		$pics_scan = scandir($dir);
		$pics = array();
		foreach ($pics_scan as $value) {
			if( $value != '.' && $value != '..'  )
			$pics[] = array('src'=> $value);
		}


		$subRequest = Request::create('/texts/'.$id);
		$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
		$editor = $response->getContent();

		$subRequest = Request::create('/sponsors/');
		$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
		$sponsors = $response->getContent();

		$subRequest = Request::create('/comments/');
		$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
		$comments = $response->getContent();

		$subRequest = Request::create('/news/');
		$response = $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
		$news = $response->getContent();


		//if(!$prj){
			return $app['twig']->render('project.html',  array('project'=>$prj, 'base_url'=>$base_url, 'user_var'=>$user_var, 'id'=>$id, 'pics_data'=>json_encode($pics), 
				'editor'=>$editor, 
				'news'=>$news, 
				'sponsors'=>$sponsors, 
				'comments'=>$comments, 
				'prj'=>$prj)  );
		/*}else{
			return '404';
		}*/

	});

	return $project
?>